﻿package core.ui.controls
{
    import core.image.*;
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.text.*;

    public class ImageInfo extends Sprite
    {
        public var URL:String;
        public var thumb:Bitmap;
        public var details:ImageDetails;
        private var border:Sprite;
        private var bg:Sprite;
        private var lb:TextField;

        public function ImageInfo(param1:ImageDetails, param2:String, param3:String)
        {
            var loader:*;
            var _arg1:* = param1;
            var _arg2:* = param2;
            var _arg3:* = param3;
            loader;
            var details:* = _arg1;
            var thumburl:* = _arg2;
            var fullurl:* = _arg3;
            this.URL = fullurl;
            this.details = details;
            this.graphics.beginFill(11184810);
            this.graphics.drawRect(0, 0, 130, 90);
            this.graphics.beginFill(16777215);
            this.graphics.drawRect(1, 1, 128, 88);
            this.graphics.beginFill(15658734);
            this.graphics.drawRect(5, 5, 120, 80);
            this.graphics.endFill();
            this.bg = new Sprite();
            this.bg.graphics.beginFill(1085418);
            this.bg.graphics.drawRect(0, 0, 130, 110);
            this.bg.graphics.beginFill(1216490);
            this.bg.graphics.drawRect(1, 1, 128, 108);
            this.bg.graphics.beginFill(16777215);
            this.bg.graphics.drawRect(4, 4, 122, 82);
            this.bg.graphics.endFill();
            this.bg.alpha = 0;
            addChild(this.bg);
            this.thumb = new Bitmap();
            this.thumb.x = 5;
            this.thumb.y = 5;
            addChild(this.thumb);
            this.lb = new TextField();
            this.lb.defaultTextFormat = new TextFormat("Verdana, Helvetica, San-serif", 10, 0, false, false, false, null, null, "center");
            this.lb.selectable = false;
            this.lb.multiline = false;
            this.lb.width = 110;
            this.lb.height = 20;
            this.lb.y = 90;
            this.lb.x = 10;
            this.lb.text = details.name != null ? (details.name) : ("");
            addChild(this.lb);
            loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function (event:Event)
            {
                var _loc_2:* = loader.content as Bitmap;
                if (loader.width != 120 && loader.height != 80)
                {
                    _loc_2.smoothing = true;
                    thumb.bitmapData = new BitmapData(120, 80, false, 16777215);
                    if (_loc_2.height / 80 < _loc_2.width / 120)
                    {
                        _loc_2.width = Math.round(_loc_2.width * (80 / _loc_2.height));
                        _loc_2.height = 80;
                    }
                    else
                    {
                        _loc_2.height = Math.round(_loc_2.height * (120 / _loc_2.width));
                        _loc_2.width = 120;
                    }
                    _loc_2.x = (120 - _loc_2.width) / 2;
                    _loc_2.y = (80 - _loc_2.height) / 2;
                    thumb.bitmapData.draw(_loc_2, _loc_2.transform.matrix);
                }
                else
                {
                    thumb.bitmapData = _loc_2.bitmapData;
                }
                return;
            }// end function
            );
            loader.load(new URLRequest(thumburl));
            return;
        }// end function

        public function set title(Verdana, Helvetica, San-serif:String) : void
        {
            this.lb.text = Verdana, Helvetica, San-serif;
            return;
        }// end function

        public function Mark(Verdana, Helvetica, San-serif:Boolean = true) : void
        {
            if (Verdana, Helvetica, San-serif && this.bg.alpha == 0 || !Verdana, Helvetica, San-serif && this.bg.alpha == 1)
            {
                if (Verdana, Helvetica, San-serif)
                {
                    this.bg.alpha = 1;
                    this.lb.textColor = 16777215;
                }
                else
                {
                    this.bg.alpha = 0;
                    this.lb.textColor = 0;
                }
            }
            return;
        }// end function

    }
}
